﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace SystemModule
{
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    public struct TDefaultMessage //Size 24
    {
        public int Recog;
        public UInt16 Ident;
        public UInt16 IdentLen;//占位符 此次不需要用用到
        public int Param;
        public int Tag;
        public int Series;
        public int nSessionID;

        public byte[] ToByte()
        {
            using (var memoryStream = new MemoryStream())
            {
                var backingStream = new BinaryWriter(memoryStream);
                backingStream.Write(Recog);
                backingStream.Write(Ident);
                backingStream.Write(IdentLen);

                backingStream.Write(Param);
                backingStream.Write(Tag);
                backingStream.Write(Series);
                backingStream.Write(nSessionID);

                var stream = backingStream.BaseStream as MemoryStream;
                return stream.ToArray();
            }
        }
    }
}
